package com.dragon.sdgp.util.defaultGenerate.strategy;

import com.dragon.sdgp.util.CommonUtil;
import com.dragon.sdgp.util.defaultGenerate.DefaultDataSources;

/**
 * @AUTHOR : Dragon_Yang
 * @File : LicensePlateStrategy
 * @DESCRIPTION :
 * @DATE : 2023/3/17 17:44
 */
public class LicensePlateGenerateStrategy implements GenerateStrategy{
    @Override
    public String createOne() {
        return createLicensePlate();
    }

    /**
     * 生成一个车牌号码
     * @return
     */
    private String createLicensePlate(){
        StringBuilder licensePlate = new StringBuilder();
        String p = CommonUtil.getOneRandomInArray(DefaultDataSources.PROVINCE_SIMPLE);
        int l = 2, n = 3;
        if(!p.equals("港") && !p.equals("澳") && !p.equals("台")){
            licensePlate.append(p);
            licensePlate.append((char) CommonUtil.getRandom('A', 'I'));
        }else {
            if(!p.equals("台")){
                n = 2;
                licensePlate.append("粤Z");
            }else {
                licensePlate.append((char) CommonUtil.getRandom('A', 'Z'));
                licensePlate.append((char) CommonUtil.getRandom('A', 'Z'));
                licensePlate.append('-');
                l = 0;
                n = 4;
            }
        }
        while (l != 0 || n != 0){
            if(CommonUtil.getRandom(2) < 1){
                if(l == 0 || n == 0){
                    if(l == 0) {
                        licensePlate.append(CommonUtil.getRandom(10));
                        n--;
                    }else {
                        licensePlate.append((char)CommonUtil.getRandom('A', 'Z'));
                        l--;
                    }
                }else {
                    if(CommonUtil.getRandom(2) < 1){
                        licensePlate.append((char) CommonUtil.getRandom('A', 'Z'));
                        l--;
                    }else {
                        licensePlate.append(CommonUtil.getRandom(10));
                        n--;
                    }
                }
            }
        }
        if(p.equals("港") || p.equals("澳")){
            licensePlate.append(p);
        }
        return licensePlate.toString();
    }
}
